﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
    //string urls = "";
    //List<Model.T_Pic> pic_list = (List<Model.T_Pic>)ViewData["Piclist"];
    var GetPicDomin = System.Configuration.ConfigurationManager.AppSettings["Pic_Domin"]+ "UploadPic/photos/";
    //if (pic_list != null && pic_list.Count > 0)
    //{
    //    var b = from o in pic_list select o.Url;
    //    urls = string.Join(",", b.ToArray());
    //}
}
<script src="~/Content/js/dialog/dialog.js"></script>
<script src="~/Content/js/common.js"></script>
<script src="~/Content/js/ajaxfileupload.js" type="text/javascript"></script>
<script type="text/javascript">
    var GetPicDomin = "@GetPicDomin";
    var keyValue = $.request("keyValue");
    //$(function () {
    //    $(":button").click(function () {
    //        ajaxFileUpload();
    //    })
    //})
    function ajaxFileUpload(obj) {
       var id = $(obj).attr("id");
        $.ajaxFileUpload
        (
            {
                url: '/PicUpload/Upload', //用于文件上传的服务器端请求地址
                secureuri: false, //是否需要安全协议，一般设置为false
                fileElementId: id, //文件上传域的ID
                dataType: 'json', //返回值类型 一般设置为json
                success: function (data, status)  //服务器成功响应处理函数
                {

                    $("#img_" + id).attr("src", GetPicDomin + data.imgurl);
                    $("#Pic_" + id).val(data.imgurl);
                    if (typeof (data.error) != 'undefined') {
                        if (data.error != '') {
                            alert(data.error);
                        } else {
                            alert(data.msg);
                        }
                    }
                },
                error: function (data, status, e)//服务器响应失败处理函数
                {
                    alert(e);
                }
            }
        )
        return false;
    }
</script>



<script>
    $(function () {
        initControl();
        if (!!keyValue) {
            $.ajax({
                url: "/templetinfo/GetFormJson",
                data: { keyValue: keyValue },
                dataType: "json",
                async: false,
                success: function (data) {
                    data.SetUpTime = new Date(data.SetUpTime).format("yyyy-MM-dd");
                    data.OpenStartTime = new Date(data.OpenStartTime).format("hh:mm");
                    data.OpenEndTime = new Date(data.OpenEndTime).format("hh:mm");
                    $("#img_f_cover_path").attr("src", GetPicDomin + data.cover_path);
                    $("#img_f_background_bottom").attr("src", GetPicDomin + data.background_bottom);
                    $("#img_f_background_path").attr("src", GetPicDomin + data.background_path);

                    
                    $("#Pic_f_cover_path").val(data.cover_path);
                    $("#Pic_f_background_bottom").val(data.background_bottom);
                    $("#Pic_f_background_path").val(data.background_path);
                    

                    if (data.is_enable == "1") {
                        $("#rd_Show").click();
                    }
                    else {
                        $("#rd_NotShow").click();
                    }
                    
                    $("#remark").val(data.remark);
                    $("#seType").val(data.category_id);
                    $("#form1").formSerialize(data);
                }
            });
        }
        gridList();
    });
    function initControl() {
        $.ajax({
            url: "/ItemsData/GetGridJson",
            data: { itemId: "43445fb8-bbb1-4883-98a2-e4ad0f28a21f" },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#seType").append("<option></option>");
                $.each(data, function (i) {
                    $("#seType").append($("<option></option>").val(data[i].F_Id).html(data[i].F_ItemName));
                });
            }
        });
    }
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        $("#HD_IsShow").val($("input[name='IsShow']:checked").val());
        $.submitForm({
            url: "/templetinfo/SubmitForm?keyValue=" + keyValue,
            param: $("#form1").formSerialize(),
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
</script>
<form id="form1">
    <div style="margin-top: 10px; margin-left: 10px; margin-right: 10px;">
        <ul class="nav nav-tabs">
            <li class="active"><a href="#">基本信息</a></li>
            @*<li ><a href="#">扩展信息</a></li>*@
        </ul>
        <div style="padding-top: 20px; margin-right: 30px;">
            <table class="form">
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 5px;">
                        模板名称
                    </th>
                    <td class="formValue" colspan="3">
                        <input id="micro_title" name="micro_title" type="text" class="form-control" placeholder="模板名称" maxlength="50" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 5px;">
                        模板备注
                    </th>
                    <td class="formValue" colspan="3">
                        <textarea id="remark" name="remark" class="form-control" style="height: 51px;" maxlength="100"></textarea>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 5px;">
                        背景宽度
                    </th>
                    <td class="formValue">
                        <input id="background_width" name="background_width" type="text" class="form-control" placeholder="背景宽度" maxlength="50" />
                    </td>
                    <th class="formTitle" valign="top" style="padding-top: 5px;">
                        背景高度
                    </th>
                    <td class="formValue">
                        <input id="background_height" name="background_height" type="text" class="form-control" placeholder="背景高度" maxlength="50" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 5px;">
                        模板类型
                    </th>
                    <td class="formValue">
                        <select id="seType" name="seType" class="form-control" style="width: 160px;"></select>
                    </td>
                    <th class="formTitle">是否显示</th>
                    <td class="formValue">
                        <div class="rdio">
                            <input id="rd_Show" name="IsShow"  type="radio" value="1"><label for="rd_Show">显示</label>
                        </div>
                        <div class="rdio">
                            <input id="rd_NotShow" name="IsShow" type="radio" value="0"><label for="rd_NotShow">不显示</label>
                        </div>
                        <input type="hidden" id="HD_IsShow" name="HD_IsShow" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 5px;">
                        分享标题
                    </th>
                    <td class="formValue" colspan="3">
                        <input id="share_title" name="share_title" type="text" class="form-control" placeholder="分享标题" maxlength="50" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">展示图</th>
                    <td class="formValue" colspan="2">
                        <img id="img_f_cover_path" width="380" height="190" />
                        <input type="file" id="f_cover_path" name="f_cover_path" style="display:none;" onchange="ajaxFileUpload(this);" />
                    </td>
                    <td>
                        <button type="button" class="btn btn-success" style="float:right;" onclick="UpdateSinglePic(1);">上传封面图片</button>
                        <input type="hidden" id="Pic_f_cover_path" name="Pic_f_cover_path">
                    </td>

                </tr>
                <tr>
                    <th class="formTitle">背景底图</th>
                    <td class="formValue" colspan="2">
                        <img id="img_f_background_bottom" width="380" height="190" />
                        <input type="file" id="f_background_bottom" name="f_background_bottom" style="display:none;" onchange="ajaxFileUpload(this);" />
                    </td>
                    <td>
                        <button type="button" class="btn btn-success" style="float:right;" onclick="UpdateSinglePic(2);">上传封面图片</button>
                        <input type="hidden" id="Pic_f_background_bottom" name="Pic_f_background_bottom">
                    </td>

                </tr>
                <tr>
                    <th class="formTitle">png图</th>
                    <td class="formValue" colspan="2">
                        <img id="img_f_background_path" width="380" height="190" />
                        <input type="file" id="f_background_path" name="f_background_path" style="display:none;" onchange="ajaxFileUpload(this);" />
                    </td>
                    <td>
                        <button type="button" class="btn btn-success" style="float:right;" onclick="UpdateSinglePic(3);">上传封面图片</button>
                        <input type="hidden" id="Pic_f_background_path" name="Pic_f_background_path">
                    </td>

                </tr>
            </table>
        </div>
    </div>
</form>
<div class="gridPanel">
    <table id="gridList"></table>
</div>
<script>
    function UpdateSinglePic(index)
    {
        switch (index) {
            case 1: $("#f_cover_path").click();; break;
            case 2: $("#f_background_bottom").click();; break;
            case 3: $("#f_background_path").click();; break;
        }
    }

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/templetinfo/GetGridJson",
            height: $(window).height() - 128,
            colModel: [
                { label: '主键', name: 'id', hidden: true },
                { label: '中文名', name: 'china_name', width: 100, align: 'left' },
                { label: '颜色', name: 'color', width: 100, align: 'left' },
                { label: '内容', name: 'content', width: 150, align: 'left' },
                { label: '类型', name: 'field_coding', width: 150, align: 'left' },
                { label: '类型编号', name: 'field_type', width: 150, align: 'left' },
                { label: '字体对齐', name: 'font_align', width: 150, align: 'left' },
                { label: '字体大小', name: 'font_size', width: 150, align: 'left' },
                { label: '字体类型', name: 'font_type', width: 150, align: 'left' },
                { label: '字体', name: 'fonts', width: 150, align: 'left' },
                { label: '高度', name: 'height', width: 150, align: 'left' },
                { label: '宽度', name: 'width', width: 150, align: 'left' },
                { label: 'x坐标', name: 'x1', width: 150, align: 'left' },
                { label: 'y坐标', name: 'y1', width: 150, align: 'left' },
                { label: '排序', name: 'sorting', width: 150, align: 'left' },
                {
                    label: '修改时间', name: 'update_time', width: 66, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return (new Date(rowObject.update_time).format("yyyy-MM-dd"));
                    }
                }
            ],
            //pager: "#gridPager",
            sortname: 'micro_id asc,update_time desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: {
                    keyword: $("#txt_keyword").val(),
                    type: $("#seType").val() == "选择类型" ? "" : $("#seType").val()
                },
            }).trigger('reloadGrid');
        });
    }

    function btn_delete() {
        $.deleteForm({
            url: "/templetinfo/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().micro_id },
            prompt: "注：您确定要删除该项数据吗？",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
</script>